package com.sgb.kjwl.view.ui.adapter.home;

import android.content.Context;
import android.graphics.Typeface;
import android.view.View;

import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ItemTabMenuViewBinding;
import com.swgk.core.view.entity.EnterpriseEditEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

public class TabMenuAdapter extends BaseRecycleAdapter<EnterpriseEditEntity> {

    //当前选中的位置
    private int currentIndex = 0;

    public TabMenuAdapter(Context context, List<EnterpriseEditEntity> data) {
        super(context, R.layout.item_tab_menu_view, data);
    }

    @Override
    public void convert(ItemViewHolder holder, EnterpriseEditEntity entity) {
        ItemTabMenuViewBinding binding = (ItemTabMenuViewBinding) holder.getmBinding();
        binding.tvTab.setText(entity.getName());
        if (currentIndex == holder.getIndex_position()) {
            binding.tvTab.setTypeface(Typeface.DEFAULT_BOLD);
        } else {
            binding.tvTab.setTypeface(Typeface.DEFAULT);
        }
        binding.tvTab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.onClick(holder.getIndex_position());
            }
        });
    }

    public void setCurrentIndex(int currentIndex) {
        this.currentIndex = currentIndex;
        notifyDataSetChanged();
    }

    public interface OnTxtItemClickListener {
        void onClick(int position);
    }

    private OnTxtItemClickListener listener;

    public void setListener(OnTxtItemClickListener listener) {
        this.listener = listener;
    }
}
